home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 April: Mac OS SDK / Dev.CD Apr 98 SDK2.toast / Development Kits (Disc 2) / ScriptX / Documentation / Code Examples from Docs / compguid / printing / winprin2 / mywin.sx < prev   
Encoding:
Text File  |  1996-05-21  |  2.0 KB  |  67 lines  |  [TEXT/ttxt]

  1. --<<<-
  2. -- Filename:
  3. --      mywin.sx
  4.  
  5. -- Purpose:
  6. --     Defines the class MyWindowClass.
  7. --     Provides an implementation for printWindow that renders the presenters
  8. --     directly to the Printer.
  9. class MyWindowClass (Window)
  10. end
  11.  
  12. method printWindow self {class MyWindowClass} -> (
  13.     local p, scaleFactor, oldRate, tmpArray, tmpSpace
  14.  
  15.     -- Create a Printer
  16.     p := new PrinterSpace
  17.     
  18.     -- We calculate the ratio of our width and height to
  19.     -- that of the Printer.The minimum of the two ratios 
  20.     -- is what we'll use to scale our bitmap.
  21.     scaleFactor := min (p.boundary.width / self.boundary.width)  \
  22.                        (p.boundary.height / self.boundary.height)
  23.  
  24.     -- Create a GroupPresenter to hold the items in our window
  25.     -- The transform goes on the GroupPresenter.
  26.     tmpSpace := new GroupPresenter
  27.     scale tmpSpace.transform  scaleFactor scaleFactor
  28.     prepend p tmpSpace
  29.  
  30.     -- This array holds all the items in our window. It 
  31.     -- needs to be around since we can't do:
  32.     --        for i in self do
  33.     --           prepend p i
  34.     -- This is because we can't iterate over the items 
  35.     -- in the window while we're deleting them from it.
  36.     tmpArray := new Array
  37.     for i in self do
  38.         append tmpArray i
  39.  
  40.     -- Bring up the printer dialog and see if we should continue
  41.     if (printerDialog p) do (
  42.         -- Stop the window's clock so we know nothing will change
  43.         oldRate := self.clock.rate
  44.         self.clock.rate := 0
  45.         self.compositor.enabled := false
  46.  
  47.         -- Move everything over to the Printer
  48.         for i in tmpArray do
  49.             prepend tmpSpace i
  50.  
  51.         -- Take a snapshot of the presentation
  52.         printFrame p
  53.         
  54.         -- Put everything back
  55.         for i in tmpArray do
  56.             prepend self i
  57.  
  58.         -- Restart the window's clock and re-enable the compositor
  59.         self.compositor.enabled := true
  60.         self.clock.rate := oldRate
  61.  
  62.         -- Flush the document
  63.         flushDocument p
  64.     )
  65. )
  66. -->>>
  67.